package edu.sctu.alex.June.day20150618;



import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;
import java.net.HttpURLConnection;
import java.net.URL;

/**
 * Created by user03 on 2015/6/18.
 */
public class HttpConnectionTest {
    public static void postTest(String path,String post1) throws IOException {

        URL url = new URL(path);
        byte[] buffer = new byte[1024*20];
        /**
         * 准备到连接到目标网址
         */
        HttpURLConnection httpURLConnection = (HttpURLConnection) url.openConnection();

        httpURLConnection.setRequestMethod("POST");//方法
        httpURLConnection.setDoInput(true);
        httpURLConnection.setDoOutput(true);
        httpURLConnection.connect();//连接到网址

        OutputStream outputStream = httpURLConnection.getOutputStream();
        outputStream.write(post1.getBytes());
        outputStream.close();

        InputStream inputStream = httpURLConnection.getInputStream();
        inputStream.read(buffer);
        System.out.println(new String(buffer,0,buffer.length,"utf-8"));

    }
}
